/*
 * Copyright (C) 2008-2009 Spark Zheng
 *
 * test/test_md5.c
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include "md5.h"
#include "sha256.h"

#include <openssl/md5.h>
#include <openssl/sha.h>

int main(int argc, char *argv[])
{
	char buf[20] = "b this is c";
	char *filename = "./test_random.c";

	char result[17] = { 0 };
	char result_openssl[17] = { 0 };
	char result_sha[33] = { 0 };
	char result_sha_openssl[33] = { 0 };

	md5_buffer(buf, 10, result);
	sha256_buffer(buf, 10, result_sha);
	MD5(buf, 10, result_openssl);
	SHA256(buf, 10, result_sha_openssl);

	uint64_t md5_big[2];
	memmove(md5_big, result, 16);
	uint64_t md5_ssl[2];
	memmove(md5_ssl, result_openssl, 16);

	uint64_t sha_big[4];
	memmove(sha_big, result_sha, 32);
	uint64_t sha_ssl[4];
	memmove(sha_ssl, result_sha_openssl, 32);


	fprintf(stdout, "%llu, %llu; %llu, %llu\n",
			md5_big[0], md5_ssl[0], md5_big[1], md5_ssl[1]);
	fprintf(stdout, "%llu, %llu; %llu, %llu;%llu, %llu; %llu, %llu\n",
			sha_big[0], sha_ssl[0], sha_big[1], sha_ssl[1],
			sha_big[2], sha_ssl[2], sha_big[3], sha_ssl[3]);


	FILE *fp;

	fp = fopen(filename, "r");

	md5_stream(fp, result);
	sha256_stream(fp, result_sha);

	fprintf(stdout, "%s\n", result);
	fprintf(stdout, "%s\n", result_sha);

	fclose(fp);

	return 0;
}
